<template>
  <div id="trictTrain">
    <div class="head">
      <span class="l-head">{{ tickinfo.flightNumber }}</span>
      <span class="r-head"><i class="iconfont iconCombinedShape"></i></span>
    </div>
    <!-- 起始站信息 -->
    <div class="station">
      <div class="l-station">
        <p>{{ tickinfo.departCity }}<span> 站</span></p>
        <span>{{ startStation }}</span>
      </div>
      <div class="m-station">
        <span>{{ tickinfo.trainNumber }}次</span>
        <img :src="imgJT" />
        <!-- <i class="iconfont iconlujing"></i> -->
      </div>
      <div class="r-station">
        <p>{{ tickinfo.arriveCity }}<span> 站</span></p>
        <span>{{ endStation }}</span>
      </div>
    </div>
    <!-- 其他信息 -->
    <div class="other-station">
      <div class="row">
        <p class="sj">{{ tickinfo.invoiceDate }}</p>
        <p class="cc"></p>
      </div>
      <div class="row">
        <p class="je">￥{{ toDecimal2(tickinfo.fare) }}元</p>
        <p class="lb">{{ tickinfo.seatLevel }}</p>
      </div>
      <div class="row note">限乘当日当次车</div>
      <div class="row identify">{{ tickinfo.identityNumber }}&nbsp;&nbsp;{{ tickinfo.passenger }}</div>
    </div>
    <p class="foot">{{ tickinfo.electronicTicketNumber }}</p>
    <div id="qrimg">
      <canvas id="qrimg000"></canvas>
    </div>
  </div>
</template>

<script>
import $ from 'jquery';
import QRCode from 'qrcode';
import pinyin4js from 'pinyin4js';
import popdata from "./common";
export default {
  mixins: [ popdata ],
  components: {},
  props: {
    tickinfo: {}
  },
  data() {
    return {};
  },
  created() {},
  mounted() {
    this.createQR();
  },
  methods: {
    createQR() {
      this.$nextTick(() => {
        let i = this.tickinfo;
        var qrInfo = [ i.flightNumber, i.departCity, i.arriveCity, i.trainNumber, i.invoiceDate, i.fare, i.identityNumber, i.passenger, i.electronicTicketNumber ];
        console.log(qrInfo);
        var qrimg000 = document.getElementById('qrimg000');
        QRCode.toCanvas(qrimg000, qrInfo,{width:108,height:108,margin:1}, function(error) {
          if (error) {
            console.error(error);
          } else {
            console.log('QRCode success!');
          }
        });
      })
    }
  },
  computed: {
    startStation() {
      return pinyin4js.convertToPinyinString(this.tickinfo.departCity || '', '', pinyin4js.WITHOUT_TONE);
    },
    endStation() {
      return pinyin4js.convertToPinyinString(this.tickinfo.arriveCity || '', '', pinyin4js.WITHOUT_TONE);
    }
  },
  watch: {}
};
</script>

<style scoped lang="scss">
#trictTrain {
  * { box-sizing: border-box; margin: 0; padding: 0; }
  width: 580px;
  height: 360px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #ecf9ff;
  border: 1px solid #c9caca;
  border-radius: 10px;
  box-sizing: border;
  padding: 15px 28px 0 26px;
  .head {
    height: 43px;
    line-height:43px;
    .l-head {
      color: #DB4F26;
      font-size: 30px;
      -webkit-background-clip:text;
      font-family: 'PingFangSC-Regular,PingFang SC';
    }
    .r-head {
      float: right;
      font-size: 24px;
      color: #000000;
      line-height: 37px;
      margin-right: 50px;
      margin-top: 8px;
      i {
        position: absolute;
        font-size: 34px;
        top: 20px;
        right: 28px;
        color: #000;
      }
    }
  }
  .station {
    width: 100%;
    height: 80px;
    overflow: hidden;
    > div {
      display: inline-block;
      text-align: center;
      vertical-align: middle;
      > p {
        font-size: 32px;
        font-family: 'BT2';
        > span {
          font-size: 17px;
        }
      }
      > span {
        line-height: 33px;
        font-size: 24px;
        display: block;
        color: #333;
        font-family:'PingFangSC-Regular,PingFang SC';
      }
      > i {
        font-size: 12px;
        display: block;
        color: #000;
        margin-top: 3px;
        transform: scale(.8);
      }
      &.l-station, &.r-station {
        width: 35%;
        vertical-align: top;
      }
      &.m-station {
        width: 28%;
      }
      &.m-station img {
        position: absolute;
        width: 180px;
        left: 50%;
        transform: translate(-46%);
        height: 12px;
        top: 96px;
      }
    }
  }
  .other-station {
    padding: 16px 26px 16px 0;
    box-sizing: border-box;
    .row {
      overflow: hidden;
      p {
        &:nth-child(1) {
          float: left;
        }
        &:nth-child(2) {
          float: right;
          color: #000;
        }
        &.sj, &.cc {
          font-size: 22px;
          line-height: 30px;
        }
        &.je {
          font-size: 26px;
          line-height: 38px;
        }
        &.lb {
          font-size: 18px;
          line-height: 25px;
          padding: 6px 18px 0 0;
        }
      }
      &.note {
        font-size: 18px;
      }
      &.identify {
        color: #000000;
        font-size: 20px;
        line-height: 28px;
        padding-top: 22px;
      }
    }
  }
  .foot {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 45px;
    line-height: 45px;
    background-color: #b3dde9;
    border-radius: 0 0 4px 4px;
    padding-left: 26px;
    font-size: 18px;
  }
  #qrimg {
    width: 108px;
    height: 108px;
    position: absolute;
    bottom: 32px;
    right: 62.8px;
    canvas {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
